<template>
  <section class='f-shop'>
    <van-cell-group class="f-cell-group">
      <van-cell value="内容" is-link class="f-shop-name">
        <template #title>
          <section class="f-name-title">
            <img class="f-img1" src="@/assets/icons/icon_shop_head@2x.png" alt="">
            <p class="f-text1 f-ml-10">{{shopForm.shopName}}</p>
          </section>
        </template>
        <template #value>
          <a @click="pageJump('update')">编辑</a>
        </template>
      </van-cell>
      <van-cell title="店铺二维码" is-link :value="shopForm.shopCode" @click="pageJump('cardQr',shopForm.shopCode)">
        <template #value>
          <qrcode-vue :value="shopForm.shopCode" :size="24" level="H" />
        </template>
      </van-cell>
      <van-cell title="邀请码" :value="shopForm.shopCode">
        <template #value>
          <section class="f-flex-right">
            <p class="f-mr-10">{{shopForm.shopCode || '--'}}</p>
            <van-button type="primary" round plain size="mini" @click="handleCopy(shopForm.shopCode)">
              &nbsp;&nbsp;复制&nbsp;&nbsp;
            </van-button>
          </section>
        </template>
      </van-cell>
      <van-cell title="联系人" :value="shopForm.contactsName" />
      <van-cell title="联系电话" :value="shopForm.contactsPhone" />
    </van-cell-group>

    <van-cell-group class="f-cell-group f-mt-15">
      <van-cell title="店铺类型" :value="shopForm.auditStatus">
        <template #value>
          <p>{{shopForm.auditStatus == 1? '个人': '公司'}}</p>
        </template>
      </van-cell>
      <van-cell v-if="shopForm.auditStatus == 2" title="企业名称" :value="shopForm.companyName">
        <template #value>
          <p>{{shopForm.companyName || '--'}}</p>
        </template>
      </van-cell>
      <van-cell title="实名认证" :value="shopForm.certificationStatus">
        <template #value>
          <p :style="{'color': shopForm.certificationStatus == 0? '#FC8683': '##3273F4'}">
            {{shopForm.certificationStatus == 0? '未实名': '已实名'}}
          </p>
        </template>
      </van-cell>
    </van-cell-group>

    <van-cell-group class="f-cell-group f-mt-15">
      <van-cell title="我的上级" :value="shopForm.supplierShopName"></van-cell>
      <van-cell title="联系人" :value="shopForm.supplierContactsName"></van-cell>
      <van-cell title="联系电话" :value="shopForm.supplierContactsPhone"></van-cell>
    </van-cell-group>
  </section>
</template>
<script>
import { ref, reactive, toRefs, onMounted, watch } from 'vue';
import { useRouter, useRoute } from 'vue-router'
import { useStore } from "vuex";
import { getStore, successDeal } from '@/utils/utils';
import QrcodeVue from 'qrcode.vue'
import api from '../api'

export default {
  components: { QrcodeVue },

  setup(props, context) {
    const store = useStore()

    const router = useRouter()
    const route = useRoute();

    const state = reactive({
      shopForm: {},
    })

    onMounted(() => {
      store.commit("setNavBar", {
        title: '店铺信息',
        show: true,
        left: true,
        leftType: 'back',
        right: false,
        rightType: 'search',
      });

      getShopInfo()
    })

    const getShopInfo = () => {
      api.shopInfo().then(res => {
        state.shopForm = res.data
      })
    }

    function handleCopy(value) {
      const input = document.createElement('input');
      document.body.appendChild(input);
      input.setAttribute('value', value);
      input.select();
      if (document.execCommand('copy')) {
        document.execCommand('copy');
        successDeal('复制成功！')
      }
      document.body.removeChild(input);
    }

    const pageJump = (name) => {
      router.push({
        path: `/more/shop/${name}`
      })
    }

    return {
      ...toRefs(state),
      pageJump,
      handleCopy
    }
  }
}
</script>
<style lang='scss' scoped>
.f-shop {
  padding: 11px 16px;
  .f-cell-group {
    width: 344px;
    padding: 5px;
    background: #ffffff;
    box-shadow: 0px 2px 6px 0px rgba(0, 51, 119, 0.1);
    border-radius: 10px;
    .f-shop-name {
      height: 70px;
      display: flex;
      align-items: center;
      .f-name-title {
        display: flex;
        align-items: center;
        position: absolute;
        top: 7px;
      }
    }
  }
  .f-img1 {
    width: 47px;
    height: 47px;
  }
  .f-text1 {
    font-weight: 500;
    font-size: 17px;
    color: #000000;
  }
}
</style>